app.controller("z-attendanceLook-c", [ '$scope','$rootScope','$z-http','$sce','z-attendance-s','z-dictionary-s','z-corporation-s','z-department-s','z-role-s','z-edit-menu-s','$filter',
		function($scope,$rootScope,$zhttp,$sce,Service,DictionaryService,CorporationService,DepartmentService,RoleService,MenuService,$filter) {
		$scope.viewModel = {};
		$scope.viewModel.perPage = "10";
		$scope.viewModel.rowCount = "1";		  
		$scope.viewModel.manuList=[];
		$scope.viewModel.corporationName=null;
		$scope.viewModel.departmentName=null;
		var now = new Date();                    //当前日期     
		var nowMonth = now.getMonth();           //当前月     
		var nowYear=$filter('date')(now,'yyyy'); //当前年
		$scope.viewModel.employeeIsSeparated=null;
		$scope.viewModel.regionType=null;
		$scope.viewModel.employeeNo=null;
		$scope.viewModel.roleName=null;
		$scope.viewModel.departmentList=[];
		$scope.viewModel.attendanceStateList=[];
		$scope.viewModel.corporationList=[];
		$scope.viewModel.employeeList=[];
		$scope.viewModel.level=null;
		$scope.viewModel.descSort=true;
		// 定义当前时间
		$scope.viewModel.effectiveDate = new Date();
		//下拉多选框长度
		$scope.multiSelectMaxHeight=300;
		//获取当月开始日期
		var monthStartDate = $filter("date")(new Date(nowYear, nowMonth, 1), "yyyy/MM/dd");
		//获取当前日期
        var dayEndDate= $filter("date")(now, "yyyy/MM/dd");
		$scope.viewModel.attendanceStratDate=new Date(monthStartDate);  //起止日期
		$scope.viewModel.attendanceEndDate=new Date(dayEndDate);	  	  //终止日期
		
		//异常信息定义
		$scope.viewModel.shouldAttendanceTime="";	//应出勤工时
		$scope.viewModel.attendanceTime="";	//出勤工时
		$scope.viewModel.leaveNumber="";	//请假次数
		$scope.viewModel.leaveDay="";	//请假天数
		$scope.viewModel.leaveTime="";	//请假时间
		$scope.viewModel.lateNumber="";	//迟到次数
		$scope.viewModel.lateHours="";	//迟到时间
		$scope.viewModel.leaveEarlyNumber="";	//早退次数
		$scope.viewModel.leaveEarlyHours="";	//早退时间
		$scope.viewModel.retroactiveNumber="";	//补签次数
		$scope.viewModel.absenteeismNumber="";	//旷工次数
		//日期控件
		$scope.viewModel.dateOptions = {
				formatYear: 'yy',
			    startingDay: 1,
			    showWeeks:false
		};
		//日期控件
		$scope.viewModel.format = "yyyy/MM/dd";
		//日期启动开关
		$scope.viewModel.startDateOpened = false;
		$scope.viewModel.endDateOpened = false;
		
		//查询页面名称
		MenuService.getMenuByUrl({url:'attendanceLook'},
		function(data){	
			$scope.viewModel.menuList=data;
		},function(error) {});
		
		//起止日期选择
		$scope.viewModel.startDateOpen = function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			 $scope.viewModel.startDateOpened = !$scope.viewModel.startDateOpened;
		};
		//起止日期选择
		$scope.viewModel.endDateOpen = function($event) {
			$event.preventDefault();
			$event.stopPropagation();
			 $scope.viewModel.endDateOpened = !$scope.viewModel.endDateOpened;
		};
		
		//加载信息
		$scope.viewModel.bindSelectRegionTypeData = function(){
			//查询公司
			CorporationService.getCorporationList({
				fromDate:$scope.viewModel.effectiveDate,
			},
			function(data){
				var site = [];  
		        $.each(data, function(index, values) {  
		            site.push({  
		                label : "("+values.corporationCode+")"+values.corporationName,  
		                value : values.corporationCode  
		            });  
		        });  
		        $('#aLCorporation').multiselect('dataprovider',site);
			},function(error) {
				
			});
		};
		$scope.viewModel.bindSelectRegionTypeData();
		
	
		/*******使用为下拉带勾选控件*********/
		//员工级别
		$('#aLlevel').multiselect({
			includeSelectAllOption: true,
			enableFiltering: true,
			delimiterText: '; ',
            maxHeight: $scope.multiSelectMaxHeight
        });
		//公司
		$('#aLCorporation').multiselect({
			includeSelectAllOption: true,
			enableFiltering: true,
			delimiterText: '; ',
            maxHeight: $scope.multiSelectMaxHeight
        });
		//公司选中事件
		$("#aLCorporation").change(function(){  
			var value=$(this).val();
		    var data={};
		    data.corporationCodeList=value;
		    data.fromDate = $scope.viewModel.effectiveDate;
		    if(value==null){
		    	var site = [];  
		    	$('#aLDepartmentName').multiselect('dataprovider',site);
		    	$scope.viewModel.departmentList=[];
		    }else{
		    	//查询部门
			    DepartmentService.getDepartmentListByCorporationCodeList(data,
				function(data){
			    	var site = [];  
			        $.each(data, function(index, values) {  
			            site.push({  
			                label : "("+values.departmentCode+")"+values.departmentName,  
			                value : values.departmentCode  
			            });  
			        });  
			        $('#aLDepartmentName').multiselect('dataprovider',site);
				},function(error) {
					
				});
		    }
        });  
		
		//部门
		$('#aLDepartmentName').multiselect({
			includeSelectAllOption: true,
			enableFiltering: true,
			delimiterText: '; ',
            maxHeight: $scope.multiSelectMaxHeight
        });
		
		//加载考勤状态数据
		$scope.viewModel.bindSelectData = function(){
			Service.getDictionaryListBydicCls({
				dicCls:"1"
			},
			function(data){
				var site = [];  
		        $.each(data, function(index, values) {  
		            site.push({  
		                label : values.dicName,  
		                value : values.dicCd  
		            });  
		        });  
		        $('#aLattendanceState').multiselect('dataprovider',site);
			},function(error) {
						
			});
			//考勤状态
			$('#aLattendanceState').multiselect({
				includeSelectAllOption: true,
				enableFiltering: true,
				delimiterText: '; ',
	            maxHeight: $scope.multiSelectMaxHeight
	        });
			Service.getDictionaryListBydicCls({
				dicCls:"2"
			},
			function(data){
				$scope.viewModel.isRepairedData = data;
			},function(error) {
						
			});
			
			Service.getDictionaryListBydicCls({
				dicCls:"3"
			},
			function(data){
				$scope.viewModel.isApprovaledData = data;
			},function(error) {
						
			});
		};
		$scope.viewModel.bindSelectData();
		
		//加载数据
		$scope.viewModel.bindData = function(){
			$scope.viewModel.employeeList=[];
			if($scope.viewModel.employeeNo!=null){
				var employeeNoData = $scope.viewModel.employeeNo.split("\n");
				for(var i=0;i<employeeNoData.length;i++){
					$scope.viewModel.employeeList.push(employeeNoData[i]);
				}
			}
			$scope.viewModel.isLoading=true;
			//获取异常信息
			
			//获取基本信息
			Service.getAttendanceList({
				descSort:$scope.viewModel.descSort,
				pageNo:$scope.viewModel.rowCount,
				pageCount:$scope.viewModel.perPage,
				attendanceDateStart:$scope.viewModel.attendanceStratDate,
				attendanceDateEnd:$scope.viewModel.attendanceEndDate,
				attendanceStateList:$scope.viewModel.attendanceStateList,
				corporationList:$scope.viewModel.corporationList,
				departmentList:$scope.viewModel.departmentList,
				employeeList:$scope.viewModel.employeeList,
				employeeLevelList:$scope.viewModel.employeeLevelList,
				isRepaired:$scope.viewModel.isRepaired,
				isApprovaled:$scope.viewModel.isApprovaled,
				roleType:true
			},
			function(data){
				$scope.viewModel.dataList = data.attendanceBeanList;
				$scope.viewModel.totalData = data.pageTotal;
				$scope.viewModel.isLoading=false;
			},function(error) {
				$scope.viewModel.isLoading=false;
			});
		};
		
		$scope.viewModel.bindData();
		
		//验证
		$scope.viewModel.validForm= function(isValid) {
            if (!isValid) {
                return;
            }else{
            	if($scope.viewModel.attendanceStratDate>$scope.viewModel.attendanceEndDate){
            		$scope.form.attendanceEndDate.$invalid=true;
            	}else{
            		$scope.form.attendanceEndDate.$invalid=false;
            		$scope.viewModel.rowCount=1;
                	$scope.viewModel.bindData();
            	}
            }
        };
        $scope.viewModel.exportData= function() {
        	$scope.viewModel.employeeList=[];
			if($scope.viewModel.employeeNo!=null){
				var employeeNoData = $scope.viewModel.employeeNo.split("\n");
				for(var i=0;i<employeeNoData.length;i++){
					$scope.viewModel.employeeList.push(employeeNoData[i]);
				}
			}
			$scope.viewModel.isLoading=true;
        	//导出
			Service.getAttendanceURL({
				employeeList:$scope.viewModel.employeeList,
				employeeLevelList:$scope.viewModel.employeeLevelList,
				corporationList:$scope.viewModel.corporationList,
				departmentList:$scope.viewModel.departmentList,
				isApprovaled:$scope.viewModel.isApprovaled,
				isRepaired:$scope.viewModel.isRepaired,
				attendanceDateStart:$scope.viewModel.attendanceStratDate,
				attendanceDateEnd:$scope.viewModel.attendanceEndDate,
			},
			function(data){
				$scope.viewModel.isLoading=false;
				window.location.href = data;
			},function(error) {
				$rootScope.alertError(error.fault.message);
				$scope.viewModel.isLoading=false;
			});
        };
        
        //控制升序，降序
        $scope.viewModel.order=function(){
        	if($scope.viewModel.descSort){
        		$scope.viewModel.descSort=false;
        	}else{
        		$scope.viewModel.descSort=true;
        	}
        	if($scope.viewModel.attendanceStratDate>$scope.viewModel.attendanceEndDate){
        		$scope.form.attendanceEndDate.$invalid=true;
        	}else{
        		$scope.form.attendanceEndDate.$invalid=false;
        		$scope.viewModel.rowCount=1;
            	$scope.viewModel.bindData();
        	}
        };
		//加载
		$scope.viewModel.loadSelect=function(){
			$scope.viewModel.showSelect=true;
		};
		//关闭加载
		$scope.viewModel.unLoadSelect=function(){
			$scope.viewModel.showSelect=false;
		};
		
		// 查看过程
		$scope.viewModel.selectUser = function(attendance){
			$scope.viewModel.isLoading=true;
			Service.getAttendanceRight({
				employeeNo:attendance.employeeNo,
				attendanceDate:attendance.attendanceDate
			},
			function(data){
				$scope.viewModel.attendanceRightBean = data;
				$scope.viewModel.isLoading=false;
				$scope.viewModel.title="查看考勤状态详细信息";
				$scope.viewModel.loadSelect();
			},function(error) {
				$rootScope.alertError(error.fault.message);
				$scope.viewModel.isLoading=false;
			});
			
		};
} ]);